<?php defined('SYSPATH') OR die('No direct access allowed.');

class html extends html_Core
{
	/** a helper function: constructs the class=.. substring */
	public static function classQ($class) {
		return $class ? " class='$class'" : '';
	}

	/** html escape */
	public static function hE($text) {
		return self::specialchars($text);
	}

	/** html escape and quote */
	public static function hQ($text,$quote='"') {
		return $quote.self::hE($text).$quote;
	}

	public static function center($t='',$class='',$extra='') {
		return self::_html_elem('center',$t,$class,$extra);
	}

	public static function div($t='',$class='',$extra='') {
		return self::_html_elem('div',$t,$class,$extra);
	}

	public static function span($t='',$class='',$extra='') {
		return self::_html_elem('span',$t,$class,$extra);
	}

	/** html element (private function) */
	private static function _html_elem($elem,$t='',$class='',$extra='') {
		if($class) $class = ' class="'.implode(' ',util::asArray($class)).'"';
		if($extra) $extra = " $extra";
		return "<$elem$class$extra>$t</$elem>";
	}

	/** html single tag element (private function) */
	private static function _html_elem1($elem,$class='',$extra='') {
		if($class) $class = ' class="'.implode(' ',asArray($class)).'"';
		if($extra) $extra = " $extra";
		return "<$elem$class$extra/>";
	}

	public static function nbsp() {
		return '&nbsp;';
	}

	/** either $t, or nbsp if $t is empty */
	public static function nbspQ($t='') {
		return util::iif(trim($t),self::nbsp());
	}

	public static function a($t,$href,$class='',$onClick='') {
		return html::a_raw($t,$href,$class,$onClick);
	}

	/** a raw anchor (private function */
	public static function a_raw($t,$href,$class='',$onClick='') {
		$href = self::hQ($href);
		if($onClick) $onClick = " onclick=\"$onClick\"";
		return self::_html_elem('a',$t,$class,"href=$href$onClick");
	}

	public static function img($src,$alt='') {
		$alt = ' alt='.self::hQ($alt);
		return self::_html_elem1('img','',"border='0' src='$src'$alt");
	}

	/** an image link */
	public static function aimg($src,$alt,$href,$class='',$onClick='') {
		return self::a_raw(self::img($src,$alt),$href,$class,$onClick);
	}

	//--- scripts -----------------------------------------------------

	public static function jscript($script,$src='') {
		if ($src) $src = " src='$src'";
		return
<<<HEREDOC
<script type='text/javascript'$src><!--
		$script
//--></script>
HEREDOC;
	}
}

// eof

//
////--- elements ----------------------------------------------------
//
//
//
//
//
//
///** link */
//
//function anchor($id) {
//	return _html_elem('a','','',"id='$id'");
//}
//
//
//
///** a header
// * @param $level 1 to ...
// */
//function h($level,$t,$class='') {
//	return _html_elem("h$level",hE($t),$class);
//}
//
//function h1($t,$class='') {
//	return h(1,$t,$class);
//}
//
//function h2($t,$class='') {
//	return h(2,$t,$class);
//}
//
//function h3($t,$class='') {
//	return h(2,$t,$class);
//}
//
//function h4($t,$class='') {
//	return h(2,$t,$class);
//}
//
//
///** other */
//function br() {
//	return self::_html_elem1('br');
//}
//

